<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ComplaintsApiController extends AbstractRestfulController
{
    public function getList()
    {
    }
    public function get($user_id)
    {		
		header('Access-Control-Allow-Origin: *');
		$complaintsTable=$this->getServiceLocator()->get('Models\Model\ComplaintsFactory');			
		$getComplaints = $complaintsTable->getComplaints($user_id)->toarray();
		if(count($getComplaints)!=0){
			return new JsonModel(array(
				'output'		=> 'success',
				'complaints'	=>	json_encode($getComplaints),
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
			));
		}
    }
    public function create($complaint)
    {
		header('Access-Control-Allow-Origin: *');
		$complaintsTable=$this->getServiceLocator()->get('Models\Model\ComplaintsFactory');			
		$postComplaint = $complaintsTable->postComplaint($complaint);
		if($postComplaint!=0){
			return new JsonModel(array(
				'output'		=> 'success',
				'complaint_id'	=>	$postComplaint,
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
			));
		}
    }
    public function update($id, $s_eamil)
    {
		header('Access-Control-Allow-Origin: *');
		$subscribeTable=$this->getServiceLocator()->get('Models\Model\SubscribeFactory');	
		if(!empty($s_eamil['email'])){
			$check_email_status = $subscribeTable->checkEmail($s_eamil['email']);
			if($check_email_status==1){
				if($id==0){
					$status=0;
				}else if($id==1){
					$status=1;
				}
				$add_subscriber = $subscribeTable->unsubscribe($status,$s_eamil['email']);
				if($add_subscriber!=0){
					return new JsonModel(array(
						'success'=> 'success',
					));
				}else{
					return new JsonModel(array(
						'status'=> 'not_success',
					));
				}
			}else{
				return new JsonModel(array(
					'status'=> 'email_is_not_exists',
				));
			}
		}else{
			return new JsonModel(array(					
			  'return'=> 'nodata',
			));
		}
    }
    public function delete($id)
    {
       
    }
}